//
//  TestViewController.swift
//  ddddd
//
//  Created by 郑东喜 on 2017/3/15.
//  Copyright © 2017年 郑东喜. All rights reserved.
//  试过百度，不好使 就随便找了个网页  另外在本地的html文件中亦可以添加css进行拦截操作

import UIKit
import WebKit

class TestViewController: UIViewController {
    
    lazy var webView: WKWebView = {
        let d : WKWebView = WKWebView.init(frame: self.view.bounds)
        
        //加载远程网络的网页
        d.load(URLRequest.init(url: URL.init(string: "http://git.oschina.net/zdx5201314/OneDallor")!))
        d.navigationDelegate = self;
        return d
    }()

    override func viewDidLoad() {
        super.viewDidLoad()


        //本地加载
//        let htmlPath = Bundle.main.path(forResource: "avc", ofType: "htm")
//        
//        do {
//            let fileURL = try NSString.init(contentsOfFile: htmlPath!, encoding: String.Encoding.utf8.rawValue)
//            let baseURL = NSURL.fileURL(withPath: htmlPath! as String)
//            webView.loadHTMLString(fileURL as String, baseURL: baseURL)
//        } catch  {
//            
//        }
        
        view.addSubview(webView)
    }
}

extension TestViewController : WKNavigationDelegate {
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        
        print("\((#file as NSString).lastPathComponent):(\(#line))\n")
        self.webView.evaluateJavaScript("document.documentElement.style.webkitTouchCallout='none';", completionHandler: nil)
    }
}
